﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


using System.Windows.Controls;
using VicMessenger.DB;
using System.Windows;
using System.Windows.Media;
using System.Data;

namespace VicMessenger.Common
{

    public class CommonCls
    {

        public static int GlobalCampaignId { get; set; }
        public static int GlobalCategoryId { get; set; }

        public static string GlobalSelectedFileSource { get; set; }

        public static string GlobalSourceConnectioinString { get; set; }
        public static string GlobalDestinationConnectionString { get; set; }

        public static string GlobalSourceSqlStatement { get; set; }



        public static List<proc_CustomeFieldTemplate_SelectResult> GetStandardCustomField()
        {
            List<proc_CustomeFieldTemplate_SelectResult> modCollection = new List<proc_CustomeFieldTemplate_SelectResult>();

            modCollection.Add(new proc_CustomeFieldTemplate_SelectResult { CustomeFieldTemplateID = 1, FieldName = "Email", RealFieldName = "" });
            modCollection.Add(new proc_CustomeFieldTemplate_SelectResult { CustomeFieldTemplateID = 2, FieldName = "FirstName", RealFieldName = "" });
            modCollection.Add(new proc_CustomeFieldTemplate_SelectResult { CustomeFieldTemplateID = 3, FieldName = "MiddleName", RealFieldName = "" });
            modCollection.Add(new proc_CustomeFieldTemplate_SelectResult { CustomeFieldTemplateID = 4, FieldName = "LastName", RealFieldName = "" });

            return modCollection;

        }

        //public static List<StandardField> GetStandard()
        //{
        //    List<StandardField> st = new List<StandardField>();
        //    st.Add( new StandardField{ StandardFieldName="Email"});
        //    st.Add( new StandardField{ StandardFieldName="FirstName"});
        //    st.Add( new StandardField{ StandardFieldName="MiddleName"});
        //    st.Add( new StandardField{ StandardFieldName="LastName"});


        //    return st;

        //}

        public static string BuilderSqlConnectionString(bool WindowsAuthenticatioin, string prmServerName, string prmDatabaseName, string prmUser, string prmPassword)
        {
            try
            {
                if (WindowsAuthenticatioin == true)
                {
                    return string.Format("Server={0};Database={1};Trusted_Connection=True;", prmServerName,prmDatabaseName);
                }
                else
                {
                    return string.Format("server={0};Database={1};uid={2};password={3};", prmServerName, prmDatabaseName,prmUser, prmPassword);
                }
            }
            catch (Exception)
            {

                return "";
            }

        }

        public static childItem FindVisualChild<childItem>(DependencyObject obj) where childItem : DependencyObject
        {
            // Search immediate children     
            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
            {
                DependencyObject child = VisualTreeHelper.GetChild(obj, i);
                if (child is childItem)
                    return (childItem)child;
                else
                {
                    childItem childOfChild = FindVisualChild<childItem>(child);
                    if (childOfChild != null)
                        return childOfChild;
                }
            }
            return null;
        }


    }
}
